﻿/// <reference path="references.scss" />

$megamenu-zindex-base:          ($zindex-dropdown - 20);
$color-layers:                  $megamenu-bg $header-bg $site-bg $body-bg;
$mixed-megamenu-bg:             $megamenu-bg;

@each $color in $color-layers {
    $i: index($color-layers, $color);

    $next-color: $color;

    @if length($color-layers) < $i  {
        $next-color: nth($color-layers, $i + 1);    
    }    
    
    @if (alpha($next-color) < 1 and $next-color != transparent)  {
        $mixed-megamenu-bg: mix(rgba($color, 1), rgba($next-color, 1), alpha($color) * 100%);
    }
}

.megamenu-section .navbar {
    background: $mixed-megamenu-bg;
    padding: 0; 
}

.megamenu-container {
    --mm-nav-padding-y: 0.5em;
    --mm-link-padding-y: 0.5em;
    --mm-link-padding-x: 0.6em;
    --mm-link-gap: 0;
    --mm-link-border-radius: var(--border-radius-md);
    --mm-link-color: #{$megamenu-color};
    --mm-link-bg-active: #{$header-hover-bg};
    --mm-arrow-size: 12px;
}

.navbar-light > .megamenu-container {
    // For better specificity
    --mm-link-color: #{$megamenu-color};
    --mm-link-bg-active: #{$header-hover-bg};
} 

.navbar-inverse > .megamenu-container {
    --mm-link-color: #{$megamenu-inverse-color};
    --mm-link-bg-active: #{$header-inverse-hover-bg};
}

.megamenu {
    overflow: hidden;
    position: relative;
    width: 100%;

    // horizontal main navbar
    .navbar-nav {
        position: relative;
        white-space: nowrap;
        /* overwrites inline width */
        width: auto !important;
        transition: margin-inline-start 0.12s ease-in-out;
        margin-inline-start: 0;
        line-height: $megamenu-line-height;
        gap: var(--mm-link-gap);
        padding-block: var(--mm-nav-padding-y);

        &:after {
            content: "";
            display: table;
            clear: both;
        }
    }

    .nav-item {
        position: relative;

        > .badge {
            position: absolute;
            inset-inline-start: 3px;
            top: calc((var(--mm-nav-padding-y) * -1) + 3px);
            font-size: $font-size-xs;
        }

        > .badge-important {
            background: $primary;
            color: $color-contrast-light;
        }

        > .badge-inverse {
            background: $danger;
            color: $color-contrast-light;
        }

        &:before, 
        &:after {
            content: "";
        }

        &.active > .nav-link,
        > .nav-link:hover { 
            background: var(--mm-link-bg-active);
        }

        &.active:before, 
        &.active:after {
            position: absolute;
            content: "";
            inset-inline-end: 4px;
            border-inline: var(--mm-arrow-size) solid transparent;
            border-bottom: calc(var(--mm-arrow-size) - 2px) solid $megamenu-dropdown-bg;
        }

        &.active:before {
            bottom: 0;
            z-index: ($megamenu-zindex-base + 3);
        }

        &.active:after {
            border-bottom-color: darken($dropdown-border-color, 8%);
            bottom: 1px;
            z-index: ($megamenu-zindex-base + 2);
        }

        &.selected .nav-link:before,
        &.expanded .nav-link:before {
            content: ' ';
            display: block;
            position: absolute;
            width: 100%;
            inset-inline-start: 0;
            bottom: 1px;
            height: 3px;
            background: $header-selected-color;
        }
    }

    .nav-item + .nav-item {
        margin-inline-start: 0;
    }

    .nav-item > .nav-link {
        font-weight: $font-weight-medium;
        font-size: $megamenu-navlink-font-size;
        color: var(--mm-link-color);
        border-radius: var(--mm-link-border-radius);
    }

    .dropdown-toggle:after {
        border: none !important;
        @include fontawesome("\f107", $font-size-base);
        width: auto;
        height: auto;
        vertical-align: middle;
    }
}

.touchevents .megamenu .nav-slider {
    overflow-x: auto !important;
}

@include media-breakpoint-up(xl) {
    .touchevents .megamenu .nav-slider {
        overflow-x: auto !important;
        overflow: -moz-scrollbars-none;
        -ms-overflow-style: none;
    }

    .touchevents .megamenu .nav-slider::-webkit-scrollbar {
        width: 0 !important;
        height: 0 !important;
    }
}

// Horizontal navbar navigation buttons
.megamenu-nav {
    position: absolute;
    top: 0;
    bottom: 0;
    transition: opacity .5s ease-in-out .1s;
    opacity: 0;
    z-index: $megamenu-zindex-base;
    display: none;
    align-items: center;
    justify-content: center;

    // INFO: No logical CSS here, else directions change.
    &.alpha {
        left: 0;
        padding-right: 1rem;
        background-image: linear-gradient(to left, rgba($mixed-megamenu-bg, 0), $mixed-megamenu-bg 40%, $mixed-megamenu-bg 100%);
    }

    &.omega {
        right: 0;
        padding-left: 1rem;
        background-image: linear-gradient(to right, rgba($mixed-megamenu-bg, 0), $mixed-megamenu-bg 40%, $mixed-megamenu-bg 100%);
    }
}

.btn.megamenu-nav-btn {
    --btn-color: var(--mm-link-color);
    --btn-hover-color: var(--btn-color);
    --btn-active-shadow: none;
    --btn-hover-bg: var(--mm-link-bg-active); // #{darken($mixed-megamenu-bg, 6%)};
    --btn-active-bg: var(--btn-hover-bg); // #{darken($mixed-megamenu-bg, 10%)};
    --btn-border-color: transparent;
    --btn-hover-border-color: transparent;
    --btn-active-border-color: transparent;
    position: relative;
    margin-inline: $focus-ring-width;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: ($megamenu-zindex-base + 10);

    &:active > .megamenu-nav-btn-icon {
        opacity: 1;
    }
}

.megamenu-nav-btn-icon {
    opacity: 0.75;
    font-size: 1.5em;
}

.megamenu-blend--next .megamenu-nav--next,
.megamenu-blend--prev .megamenu-nav--prev {
    opacity: 1;
    display: flex;
}


.navbar:is(#{unquote(":hover, :focus-within")}) > .megamenu-container.show-scroll-buttons .megamenu-nav-btn {
    opacity: 1;
}

.megamenu-container {
    position: relative;

    :where(.dropdown-menu, .megamenu-dropdown) {
        --y1: 0.5em;
        --y2: calc((var(--mm-nav-padding-y) * -1) - 1px);
        @include sliding-dropdown-menu();
    }

    .show .megamenu-dropdown,
    .show > .dropdown-menu {
        display: block;
        visibility: visible;
        opacity: 1;
        transform: translateY(var(--y2));
    }

    .nav-link {
        padding: var(--mm-link-padding-y) var(--mm-link-padding-x);
    }

    .megamenu-dropdown {
        --dropdown-border-radius: var(--border-radius-xl);
        background-color: $megamenu-dropdown-bg;
        color: $megamenu-text-color;
        z-index: ($megamenu-zindex-base + 1);
        width: 100%;
        top: -3px;
        background-repeat: no-repeat;
        background-position: bottom right;
        padding: 0;
        min-height: var(--mm-drop-min-height, auto);

        label {
            vertical-align: top;
            margin-bottom: 0;
        }

        .row > div:empty {
            height: 0;
        }
    }

    .megamenu-dropdown-row {
        padding: 1.5rem;
    }

    .megamenu-col {
        display: flex;
        flex-flow: column;
        gap: 0.625rem;
    }

    .megamenu-dropdown-heading {
        position: relative;
        font-size: 1rem;
        font-weight: $font-weight-medium;
        //line-height: 1.4rem;
        text-decoration: none;
        display: inline-block;
        color: $megamenu-heading-color;
        transition: transform 0.2s ease-in-out;

        //&:after {
        //    display: inline-block;
        //    position: relative;
        //    content: '\21E2';
        //    opacity: 0;
        //    transform: translateX(-30%) scaleX(0.5);
        //    transition: all 0.15s ease;
        //}

        &:hover {
            transform: translateX(5px);
            //&:after {
            //    opacity: 1;
            //    transform: translateX(0) scaleX(1);
            //}
        }
    }

    // Product rotator 
    .rotator-container {
        border: 1px solid rgba($black, .1);
        background: $megamenu-rotator-bg;
        overflow: hidden;
	    min-height: 320px;

        .rotator-heading {
            padding: 0.5rem 0;
        }

        .rotator-content > div.placeholder {
            height: 280px;
            background-color: rgba($white, 0.85);

            .empty {
                background-color: transparent;
            }
        }
    }
}

.megamenu-dropdown-container {
    position: relative;

    &.simple {
        position: initial;
    
        .dropdown-menu {
            margin-top: -1px;
            --dropdown-min-width: 250px;
            --dropdown-zindex: #{$megamenu-zindex-base + 1};
        }

        .nav-item.active:before {
            inset-inline-end: initial;
            inset-inline-start: 12px;
        }

        .nav-item.active:after {
            inset-inline-end: initial;
            inset-inline-start: 10px;
        }
    }
}

.megamenu-cat-img-text {
    text-align: start;
    margin: 10px;
    font-size: $font-size-sm;
}

.megamenu-picture-container {
    position: absolute;
    inset-inline-end: 0;
    bottom: 0;
    pointer-events: none;
    z-index: -1;
}

.megamenu-dropdown-heading + .megamenu-subitems {
    margin-top: 3px;
}

.megamenu-subitems {
    display: flex;

    &.inline {
        flex-flow: row;
        flex-wrap: wrap;

        > .megamenu-subitem-wrap {
            display: inline-flex;
        }

        .megamenu-subitem:hover {
            text-decoration: underline;
            color: var(--gray-600);
        }
    }

    &.block {
        flex-flow: column;
        flex-wrap: nowrap;
        gap: 1px;
    }
}

.megamenu-subitem-wrap {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.megamenu-subitem {
    display: block;
    font-size: $font-size-sm;
    text-decoration: none;
    color: $megamenu-subitem-color;
    transition: color 0.1s ease;

    &:hover {
        color: inherit;
        text-decoration: none;
    }

    &.more-link {
        color: inherit;
        text-decoration: none !important;
    }
}

@include media-breakpoint-up(xl) {
	.megamenu-container .rotator-container {
		// Prevents nav-item focus loss when background image is available
		min-height: 370px;
	}
}

// Brand menu 
#dropdown-menu--10 .dropdown-menu .megamenu-dropdown-heading {
    line-height: 1.125rem;
}

.brand-menu-footer {
    background: var(--gray-100);
    border-top: 1px solid var(--gray-300);
    border-radius: 0 0 var(--border-radius-md) var(--border-radius-md);
}

.brand-menu-footer-thumb-col {
    width: 80px;
    max-width: 80px;
    min-width: 80px;
    margin: 1rem 0;
    filter: grayscale(100%);
    &:hover { filter: initial; }
}

.brand-menu-footer-thumb {
    margin: auto; 
}

.megamenu.simple .navbar-nav .nav-item {
    &.active:before {
        border-bottom: 10px solid $dropdown-bg;
    }
}

@media screen {
    .boxed .megamenu-dropdown-container.simple .dropdown-menu {
        margin-inline-start: 20px;
    }
}